05. Challenge 2

Control Flow

In this quiz, I want you to write a for loop. Your loop will live inside a function that will be passed an int, n , and a string, str . Your loop should print the str n times.

There's another twist here - you will not need to touch main.cpp this time. Instead, your code will be written inside the eponymous function in PrintString.cpp. Make note of the way that main.cpp #include s PrintString.h. You'll be #include ing files soon.

Task List:

Task Feedback:

Awesome! Make sure you test it.

Start Quiz:

#include "PrintString.h"

#include <iostream>
#include <string>

void PrintString(std::string str, int n) {
  // your code goes here! print str n times. Follow each str with a newline,
  // eg. std::cout << str << std::endl;
}
/**
 * No need to change this file (unless you want to change the test case below).
 */

#include <iostream>
#include "PrintString.h"

int main() {
  PrintString("This is a test.", 10);
}
/**
 * This header file defines the function signature for PrintString.
 */

#ifndef PRINTSTRING_H
#define PRINTSTRING_H

#include <string>

void PrintString(std::string, int);

#endif  // PRINTSTRING_H